﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace WindowsFormsApplication1.Filtry
{
    class Binaryzacja
    {
        public Bitmap bitmapFiltr { get; set; }
        private int  width, height;
        private Bitmapp bitmap;

        public Binaryzacja( int width, int height, Bitmapp bitmap)
        {
            this.width = width; this.height = height;
            this.bitmap = bitmap; 
        }

        internal System.Drawing.Bitmap ZwrocObrazekPoBinrazycacji(float value)
        {
            this.bitmapFiltr = new Bitmap(this.width, this.height);

            for (int i = 0; i < this.height; i++)
            {
                for (int j = 0; j < this.width; j++)
                {
                    
                        //bitmapFiltr.SetPixel(j, i, bitmap.GetPixel(j, i));
                   if(bitmap.GetPixelR(j,i)<value ||bitmap.GetPixelG(j,i)<value  || bitmap.GetPixelB(j,i)<value )
                       bitmapFiltr.SetPixel(j, i, Color.FromArgb(0, 0, 0));
                   else bitmapFiltr.SetPixel(j, i, Color.FromArgb(255, 255, 255));
                    
                }
            }

            return this.bitmapFiltr;
        }
    }
}
